package com.gem.controller;

import com.gem.entity.Room;
import com.gem.service.RoomService;
import com.gem.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.soap.Node;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

/**
 * Author: Xhy
 * CreateTime: 2022-09-17 23:40
 */

@RestController
@RequestMapping("/room")
@CrossOrigin
public class RoomController {

    @Autowired
    private RoomService roomService;


    /**
     * 房间列表
     * @return
     */
    @GetMapping("/page")
    public R list(@RequestParam(defaultValue = "1",required = false) Integer curPage,
                  @RequestParam(defaultValue = "15",required = false) Integer limit){
        return roomService.page(curPage,limit);
    }

    /**
     * 创建房间
     * @param room
     * @return
     */
    @PostMapping("/create")
    public R createRoom(@RequestBody Room room){

        return roomService.createRoom(room);
    }



    /**
     * 退出房间
     * @param roomId
     * @param userId
     * @return
     */
    @DeleteMapping("/quit")
    public R quitRoom(String roomId,String userId){
        return roomService.quitRoom(roomId,userId);
    }


    /**
     * 获取房间内用户
     * @param roomId
     * @return
     */
    @GetMapping("/getRoomInUsers")
    public R getRoomInUsers(String roomId){

        return roomService.getRoomInUsers(roomId);
    }

    /**
     * 搜索房间
     * @param roomId 房间号
     * @return
     */
    @GetMapping("/search")
    public R search(String roomId){

        return roomService.search(roomId);
    }
}
